var Widget=Base.extend({

	constructor : function(jwidget,wPanel){
			 
		this.panel=wPanel;		 			 
		this.jwidget=jwidget;
		// alert(jwidget);
		this.core = $(document.createElement("div")).attr('id',jwidget.wid).addClass('core').css({position:jwidget.style.position,width:jwidget.style.width}).appendTo($('.edit'));
		// this.core=$('.core');
		// this.core.attr('id',className+rnd).css({position:'absolute'})
		var me=this;
		this.core.mousedown(function(){
		  me.mousedown();	  
		});
		this.core.click(function(){
		  me.click();
		});
		this.core.mouseleave(function(){
	      me.mouseleave();
	    });
    this.core.mouseenter(function(){
        me.mouseenter();
    });
	},
	init:function(options){
		
	},
	resize : function(){
		this.core.resizable();
		var me=this;
		this.core.bind("resizestop",function(event,ui){
			//alert(ui.size.width+"|"+ui.size.height);
			me.jwidget.style.width=ui.size.width;
			me.jwidget.style.height=ui.size.height;
		});
	},
	drag:function(){
  	//this.core.append("<p class='draghandle'>������ק</p>");
	  this.core.draggable({ cursor: 'crosshair',handle:".draghandle",containment:'.edit'});
	  var me=this;

	  this.core.bind( "dragstop", function(event, ui) {
			//alert(ui.position.top+"|"+ui.position.left);.
		me.jwidget.style.top=ui.position.top;
		me.jwidget.style.left=ui.position.left;
	  });
	},
	  load:function(jwidget){
		this.jwidget=jwidget;
		me=this;
		this.core.css({left: jwidget.style.left,top: jwidget.style.top,width: jwidget.style.width,height: jwidget.style.height});
		this.core.load( JWidgetOption.coreUrl+"/load"+jwidget.classname,{'jwidget':jwidget},function(){
		  me.drag();
		  me.resize();
		  me.mouseenter();
		});
	},
	  click:function(){
	  	var hreflink='#tabs-'+this.jwidget.wid;

	  	if($("[href="+hreflink+"]").length==0){
			this.panel.add(this.jwidget);
	  	}
	  	$("#tabs").tabs( "option", "selected",this.jwidget.wid);
	  },
	  remove:function(){},
	  mousedown:function(){//alert(this.core.attr('id'));
	  },
	  mouseleave:function(){
	     me.core.removeClass('core-mouseenter');
	  },
	  mouseenter:function(){ this.core.addClass('core-mouseenter');}

});